var t = require("../../@babel/runtime/helpers/toConsumableArray"),
  a = require("../../@babel/runtime/helpers/createForOfIteratorHelper"),
  e = require("../../utils/http.js"),
  i = require("../../utils/api.js"),
  s = require("../../utils/language/switchLanguage.js");
Page({
  data: {
    lists: { page: 1, limit: 15, list: [] },
    currentTab: 0,
    refresh: !1,
    show: !0,
    chooseId: [],
    chooseData: {},
  },
  onLoad: function (t) {
    this.initLanguage(),
      this.getInvoiceList({
        page: this.data.lists.page,
        limit: this.data.lists.limit,
      });
  },
  initLanguage: function () {
    var t = s.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: t, languageType: wx.getStorageSync("language") }),
      wx.setNavigationBarTitle({ title: t["开票列表"] });
  },
  changeTab: function (t) {
    var a = t.target.dataset.idx,
      e = this.data.lists;
    (e.list = []),
      this.setData({ currentTab: a, lists: e }),
      this.getInvoiceList({ page: 1, limit: this.data.lists.limit });
  },
  changeOrder: function (t) {
    var a = {},
      e = t.detail.value;
    if (e.length > 0) for (var i = 0; i < e.length; i++) a[e[i]] = !0;
    else a = {};
    this.setData({ chooseId: e, chooseData: a });
  },
  checkAll: function () {
    var t = this.data.lists.list,
      e = this.data.chooseData,
      i = this.data.chooseId;
    if (t.length == i.length) this.setData({ chooseData: {}, chooseId: [] });
    else {
      (i = []), (e = {});
      var s,
        o = a(t);
      try {
        for (o.s(); !(s = o.n()).done; ) {
          var n = s.value;
          (e[n.orderSn] = !0), i.push(n.orderSn);
        }
      } catch (t) {
        o.e(t);
      } finally {
        o.f();
      }
      this.setData({ chooseData: e, chooseId: i });
    }
  },
  getInvoiceList: function (a, i) {
    var s = this;
    e.getInvoiceList(a, this.data.currentTab).then(function (e) {
      if (
        (void 0 !== i && i(e.data.rows),
        e.data.rows.length > 0 && !s.data.refresh)
      ) {
        var o = s.data.lists;
        (o.list = [].concat(t(o.list), t(e.data.rows))),
          (o.page = a.page),
          s.setData({ lists: o, lock: !1, total: e.data.total });
      } else if (e.data.rows && s.data.refresh) {
        var n = s.data.lists;
        (n.list = e.data.rows),
          (n.page = a.page),
          s.setData({ lists: n, refresh: !1, lock: !1, total: e.data.total });
      }
      s.setData({ show: !0 });
    });
  },
  resetInvoice: function (t) {
    var a = t.currentTarget.dataset.price,
      e = t.currentTarget.dataset.id;
    wx.navigateTo({
      url: "plugin-private://wx393d60d93f70599c/pages/invoiceing/index?totalPrice="
        .concat(a, "&id=")
        .concat(e, "&from=index"),
    });
  },
  toPage: function (t) {
    if (0 == this.data.currentTab) {
      if (0 == this.data.chooseId.length)
        return void i.showMsg(this.data._t["请先勾选需要开票的订单！"]);
      var e,
        s = this.data.lists.list,
        o = this.data.chooseId,
        n = 0,
        r = a(s);
      try {
        for (r.s(); !(e = r.n()).done; ) {
          var l = e.value;
          -1 != o.indexOf(l.orderSn) &&
            (n = (parseFloat(n) + l.totalAmount).toFixed(2));
        }
      } catch (t) {
        r.e(t);
      } finally {
        r.f();
      }
      return (
        wx.setStorageSync("chooseId", this.data.chooseId),
        void wx.navigateTo({
          url: "plugin-private://wx393d60d93f70599c/pages/invoiceing/index?totalPrice=".concat(
            n,
          ),
        })
      );
    }
    if (1 == this.data.currentTab) {
      var c = t.currentTarget.dataset.id;
      wx.navigateTo({
        url: "plugin-private://wx393d60d93f70599c/pages/invoiceInfo/index?id=".concat(
          c,
        ),
      });
    }
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {
    this.setData({ refresh: !0 }, function () {
      var t = { page: 1, limit: this.data.lists.limit };
      this.getInvoiceList(t, function (t) {
        wx.stopPullDownRefresh();
      });
    });
  },
  onReachBottom: function () {
    if (this.data.total != this.data.lists.list.length && !this.data.lock) {
      this.setData({ lock: !0 });
      var t = { page: this.data.lists.page + 1, limit: this.data.lists.limit };
      this.getInvoiceList(t);
    }
  },
});
